using MediatR;
using SumerCoreDevOps.Application.GitTriggers.Queries;
using SumerCoreDevOps.Domain.Entities;
using SumerCoreDevOps.Infrastructure.GitTrigger;

namespace SumerCoreDevOps.Application.GitTriggers.Handlers;

/// <summary>
/// 获取工作流的所有触发规则查询处理器
/// </summary>
public class GetGitTriggerRulesByWorkflowQueryHandler : IRequestHandler<GetGitTriggerRulesByWorkflowQuery, List<GitTriggerRule>>
{
    private readonly GitTriggerRuleManager _ruleManager;

    public GetGitTriggerRulesByWorkflowQueryHandler(GitTriggerRuleManager ruleManager)
    {
        _ruleManager = ruleManager;
    }

    public async Task<List<GitTriggerRule>> Handle(GetGitTriggerRulesByWorkflowQuery request, CancellationToken cancellationToken)
    {
        return await _ruleManager.GetRulesByWorkflowIdAsync(request.WorkflowId);
    }
}
